package codeTop;

public class q75 {
    public void sortColors(int[] nums) {
        int idx0 = 0,idx1 = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 0) {
                swap(nums,idx0++,i);
                if (nums[i] == 1) {
                    swap(nums,idx1++,i);
                }else {
                    idx1++;
                }
            } else if (nums[i] == 1) {
                swap(nums,idx1++,i);
            }
        }
    }
    void swap(int[] nums,int idx1,int idx2){
        int temp = nums[idx1];
        nums[idx1] = nums[idx2];
        nums[idx2] = temp;
    }
}
